<?php
include '../admin_head.php';
	
	//查询出来一个list,为pid的path值
	$pid = $_GET['id']? $_GET['id']: 0 ;
	
	//制作一个数组，下标为路径的id值为name
	if(strlen($_GET['list']) < 1){
		$list = '0';
	}else{
		$list .= $_GET['list'].','.$pid;
	}


	//$tmp = explode(',',$list);
	foreach(explode(',',$list) as $val){
		$sql = "select name from ".PRE."category where id='{$val}'";
		$temp = mysql_fetch_assoc(mysql_query($sql));
		$path[$val] = $temp['name'];
	}
	 
	//查询分类信息
	$sql = "select id,name,pid,display,path from ".PRE."category where pid='{$pid}' order by id";
	$result = mysql_query($sql);
	if($result && mysql_num_rows($result)>0){
		while($row = mysql_fetch_assoc($result)){
			$catelist[] = $row;
		}
	}
	mysql_free_result($result);
?>

	<div class="admin_main_nav">分类管理&gt;&gt;分类列表</div>
	<div id="cate_index" class="admin_main_index">
		<div class="width">
			<div class="user_index_title">
			<?php foreach($path as $id => $val):?>
			<!-- 处理回传的值 -->
			<a class="path_nav" href="index.php?id=<?php echo $id?>&list=<?php $len = strpos($list.',',','.$id.',');echo substr($list,0,$len)?>"><?php echo $id == 0 ?'顶级分类' :$val; ?></a>
			<span>&gt;</span>
			<?php endforeach;?>
			</div>
			<div>
				<table width="800" align="center">
					<tr>
						<th>类别ID</th>
						<th>类别名称</th>
						<th>所属分类</th>
						<th>状态</th>
						<th>商品数量</th>
						<th width="400">操作</th>
					</tr>
					<?php if(!empty($catelist)):?>
					<?php foreach($catelist as $tr):?>
					<tr>
						<td><?php echo $tr['id'] ?></td>
						<td><?php echo $tr['name'] ?></td>
						<td><?php echo $tr['pid'] ?></td>
						<td><?php 
							if($tr['display'] == 0) echo '<a style="color:#E95B57" href="action.php?a=dis&dis=1&id='.$tr['id'].'">隐藏</a>';
							if($tr['display'] == 1) echo '<a style="color:#468847" href="action.php?a=dis&dis=0&id='.$tr['id'].'">显示</a>';

						?></td>
						<td>wait...</td>
						<td>
							<div class="action">
							<div class="fl"><a class="view" href="index.php?id=<?php echo $tr['id'] ?>&list=<?php echo $list ?>"><div class="icon fl view_i"></div><div class="fl">查看子分类</div></a></div>
								<div class="fl"><a class="add" href="add.php?id=<?php echo $tr['id'] ?>&list=<?php echo $list ?>"><div class="icon fl add_i"></div><div class="fl">添加子分类</div></a></div>
								<div class="fl"><a class="edit" href="edit.php?pid=<?php echo $tr['pid']?>&id=<?php echo $tr['id']?>&list=<?php echo $list ?>"><div class="icon fl edit_i"></div><div class="fl">编辑</div></a></div>
								<div class="fl"><a class="del" href="action.php?a=del&id=<?php echo $tr['id']?>&pid=<?php echo $tr['pid']?>&list=<?php echo $list?>"><div class="icon fl del_i"></div><div class="fl">删除</div></a></div>
							</div>
						</td>
					</tr>
					<?php endforeach;?>
					<?php else:?>
						<tr>
							<td colspan="6">没有找到任何记录</td>
						</tr>
					<?php endif;?>
				</table>
			</div>

		</div>
	</div>

	
<?php include '../admin_footer.php'; ?>

